import Vue from 'vue'

const invoice = {
  state: {
    taxType: null,  //发票类型
    totalPrice: 0,   //开票总金额
    amountNum: 0,   //开票数量
    vatIndex: null,   //开票增值税专票下标
    vatRate: null,   //开票增值税专票税率
    vatReason: null,   //优惠政策原因
  },
  mutations: {
    //开票总金额
    setResturantTotal: (state, payload) => {
      state.totalPrice = payload;
    },
    //开票张数
    setInvoiceNum: (state, payload) => {
      // console.log('本次开票张数vuex+ ' + payload)
      state.amountNum = payload;
    },
    //增值税税率
    setInvoiceVatIndex: (state, payload) => {
      // console.log('本次选择增值税税率id ' + payload)
      state.vatIndex = payload.vatIndex;
      state.vatRate = payload.vatRate;
    },
    //优惠政策原因
    setInvoiceExplain: (state, payload) => {
      state.vatReason = payload;
    },
    //重置增值税税率
    deleteInvoiceVat: (state, payload) => {
      state.vatIndex = null;
      state.vatRate = null;
      state.vatReason = null;
    },
    //发票类型
    setInvoiceType: (state, payload) => {
      state.taxType = payload;
      if (state.taxType == 2){
        state.vatRate = 1;
      }
    },
  },
  actions: {
    // 触发获取当前点击的数据源方法
    setResturantTotal({ commit }, payload){
      commit('setResturantTotal', payload)
    },
    setInvoiceNum({ commit }, payload){
      commit('setInvoiceNum', payload)
    },
    setInvoiceVatIndex({ commit }, payload){
      commit('setInvoiceVatIndex', payload)
    },
    setInvoiceExplain({ commit }, payload){
      commit('setInvoiceExplain', payload)
    },
    deleteInvoiceVat({ commit }, payload){
      commit('deleteInvoiceVat', payload)
    },
    setInvoiceType({ commit }, payload){
      commit('setInvoiceType', payload)
    },
  }
}

export default invoice


